package com.distribute.application.manage.goods;

import java.util.*;
import java.io.File;

import com.distribute.framework.core.web.helper.Utils;
import com.distribute.framework.core.lang.*;
import com.distribute.framework.core.web.node.Export;
import com.distribute.framework.core.lang.Protocol.BeanFormat;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.web.util.*;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

import com.distribute.framework.model.*;
import com.distribute.application.api.utils.DateUtils;
import com.distribute.application.manage.*;
import com.distribute.application.utils.AlipyToUser;
import com.distribute.application.utils.WechatMouldUtil;


/************CTRL_CODE_INPORT************/
/************CTRL_CODE_INPORT************/



/**
 * 商品订单的Controller
 * @author 飞啊飘啊
 */
@SuppressWarnings({"unchecked","rawtypes"})
@flag("DirectOrder")
@RestController
@Component(value="manage.goods.directorderController")
public class DirectorderController{
	
	@flag("stuct")
	@RequestMapping("/manage/goods/directorder.list.do")
  	public Protocol list() {
  		try{
  			Protocol protocol = Protocol.create(true,null);
  			setFormDataInfo(protocol,null,null);
  			//处理页面的视图数据，比如显示哪些列，自定义显示列等
			ActionHelper.doPageViewFields(DirectOrder.class);
  			Map<String,Object> params = setDefaultSort(ActionHelper.getQueryFormParams(DirectOrder.class));
			protocol.set("PARAMS",ActionHelper.getQueryFormParams(DirectOrder.class));
			protocol.set("fields", Utils.getRequest("fields"));
			
			Integer iPage = Utils.getInteger("page", 0);
			Integer iSize = Utils.getInteger("size",16);
			
				
			params.put("merchant",LoginHelper.getLogin().getId());
				
			
			
			/************CTRL_BEFORE_LIST************/
			/************CTRL_BEFORE_LIST************/
			Page page = DirectOrder.page(iPage,iSize,params);//调用获取分页
	    	protocol.setPage(page,new BeanFormat<DirectOrder>(){
				public Map format(DirectOrder t) {
					return t.toJSON();
				}
			});
			
			/************CTRL_AFTER_LIST************/
			/************CTRL_AFTER_LIST************/
			return protocol;
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	
  	@RequestMapping("/manage/goods/directorder.export.do")
  	public Protocol export(HttpServletResponse response) {
  		try{
  			Protocol protocol = Protocol.create(true,null);
  			setFormDataInfo(protocol,null,null);
  			//处理页面的视图数据，比如显示哪些列，自定义显示列等
			ActionHelper.doPageViewFields(DirectOrder.class);
  			Map<String,Object> params = setDefaultSort(ActionHelper.getQueryFormParams(DirectOrder.class));
  			params.put("idIn", Utils.getString("ids"));
			Integer iPage = Utils.getInteger("page", 0);
			Integer iSize = Utils.getInteger("size",16);
			
				
			params.put("merchant",LoginHelper.getLogin().getId());
				
			
			
			/************CTRL_BEFORE_EXPORT************/
			/************CTRL_BEFORE_EXPORT************/
			final Map<String, Object> finalParams = params;
			//调用lazy3q.jar中的导出功能
			//参数说明：(这次导出多少条数据，到数据库查的时候一次查多少条，当前所在第几页,处理器，对应的模型类,要导出哪些字段)
			Utils.export(DirectOrder.count(params).intValue(), 100, 0 , new Export(){//new Export这个类，他会根据参数分次查询，边查边写，目的只有一个，就是为了避免把大量的数据放在内存中
				@Override //重载实现Export的getPage方法，Export会分多次调用这个方法
				public Page getPage(Integer page, int size) {//这时的page和size是Export转化过后的当前页，每页查询数					
					return DirectOrder.getDirectOrderPage(page, size, finalParams);
				}
			}, DirectOrder.class, Utils.getString("fields").split(","));
			
			/************CTRL_AFTER_EXPORT************/
			/************CTRL_AFTER_EXPORT************/
			return null;
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	 
  	
  	
  	@flag("stuct")
  	@RequestMapping("/manage/goods/directorder.get.do")
  	public Protocol get() {
  		try{
  			Protocol protocol = Protocol.create(true,null).set("directOrder",new HashMap());
  			DirectOrder directOrder = Utils.getObject("", DirectOrder.class);
  			if(directOrder!=null){
				protocol.set("directOrder",directOrder.toJSON());
			}
			Long id=Utils.or(Utils.getLong("id"),Utils.getLong("key"));
			String edittype = Utils.getString("edittype");
			
			if(id==null){
				
				setFormDataInfo(protocol,edittype,null);
				return protocol.reset(false,null,"args-id-null");
			}			
			directOrder=DirectOrder.where.id(id).get();
			if(directOrder==null){
				return protocol.reset(false,"数据不存在","data-not-exist");
			}
			setFormDataInfo(protocol,edittype,directOrder);
			
				
			if(directOrder.getMerchant().longValue()!=LoginHelper.getLogin().getId().longValue()){
				protocol.reset(false,"没有权限访问数据","host-no-mate");
				directOrder=null;
			}
				
			
			protocol.set("directOrder",directOrder.toJSON());
			
			
			
			if(Utils.equals(Utils.getString("edittype"), "send")){//表单[平台发货]
				
					
				/************LAZY3Q_FORM_UNDEFINE_平台发货************/
				/************LAZY3Q_FORM_UNDEFINE_平台发货************/
				
			}
			
			if(Utils.equals(Utils.getString("edittype"), "adopt")){//表单[退款审核通过]
				
					
				/************LAZY3Q_FORM_UNDEFINE_退款审核通过************/
				/************LAZY3Q_FORM_UNDEFINE_退款审核通过************/
				
			}
			
			if(Utils.equals(Utils.getString("edittype"), "refuse")){//表单[退款审核拒绝]
				
					
				/************LAZY3Q_FORM_UNDEFINE_退款审核拒绝************/
				/************LAZY3Q_FORM_UNDEFINE_退款审核拒绝************/
				
			}
			
			
			
			
			/************CTRL_CODE_GET************/
			/************CTRL_CODE_GET************/
			return protocol;
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	
  	
  	@limitVal(2)//查看权限
  	@RequestMapping("/manage/goods/directorder.insert.do")
  	public Protocol insert() {
  		try{
			final String requestToken = Utils.getString("directOrderToken");
			final Date lastToken = Utils.getSession(requestToken);
			if(lastToken==null || (new Date().getTime()-lastToken.getTime())>10000){
				if(requestToken!=null)Utils.setSession(requestToken,new Date());//放入Token时间戳	
				DirectOrder.execute(new Function(){
					public <T> T execute(Object... arg0){
						
						/************CTRL_BEFOR_INSERT************/
						/************CTRL_BEFOR_INSERT************/
						DirectOrder directOrder = Utils.getObject("directOrder", DirectOrder.class);
						
						//批量插入处理
						String vValue = ""+(directOrder.getNo()==null?"":directOrder.getNo());
						String sArray[]={""+vValue};
						
						if(vValue.startsWith("[*]")){
							vValue=vValue.replace("[*]","");
							sArray=vValue.split("[\\s|\u3000|\\u00a0|,]+");		
						}
						
						for(String sItem:sArray){
							if(!Utils.empty(sItem))
							directOrder.setNo(String.valueOf(sItem));
							//设置默认值
							setDefaultValue(directOrder,"insert");
							
							
								
							directOrder.setMerchant(LoginHelper.getLogin().getId());
								
							
							
							
								/************CTRL_BEFORE_ADD************/
								/************CTRL_BEFORE_ADD************/
							DirectOrder.saveDirectOrder(directOrder);	
							
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
								
							
									
								
							
							
							
							
								/************CTRL_AFTER_ADD************/
								/************CTRL_AFTER_ADD************/
						}
						
						//记录操作日志
						LoggerHelper.writeLog(DirectOrder.class,"add","添加了[商品订单]["+directOrder.getNo()+"]",LoginHelper.getUserId(), directOrder,directOrder.getId());
						
						return null;
					}
				});
				
			}else{
				throw new DefineException("repeat-submit-error","对不起，请勿重复提交"+(10-((new Date().getTime()-lastToken.getTime())/1000))+"秒后再试");
			}
			
			/************CTRL_AFTER_INSERT************/
			/************CTRL_AFTER_INSERT************/
			return Protocol.create(true,"添加[商品订单]数据成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	
  	
  	@limitVal(4)//修改权限
  	@RequestMapping("/manage/goods/directorder.update.do")
  	public Protocol update() {
  		try{
			final String requestToken = Utils.getString("directOrderToken");
			final Date lastToken = Utils.getSession(requestToken);
			if(lastToken==null || (new Date().getTime()-lastToken.getTime())>10000){
				if(requestToken!=null)Utils.setSession(requestToken,new Date());//放入Token时间戳	
				DirectOrder.execute(new Function(){
					public <T> T execute(Object... arg0){
						
						/************CTRL_BEFOR_UPDATE************/
						/************CTRL_BEFOR_UPDATE************/
						DirectOrder directOrder = Utils.getObject("directOrder", DirectOrder.class);
						DirectOrder oldDirectOrder = null;
						String PARAMS = Utils.getString("PARAMS");
						String ids=Utils.getString("ids");
						if(!Utils.empty(PARAMS)){//根据查询条件批量更新
							Map params = Utils.eval(PARAMS);
							params.put("confirm", 1);
							params.put("definex","1=1");
							
							
							
								
							directOrder.setMerchant(LoginHelper.getLogin().getId());
								
							
							
							DirectOrder.updateDirectOrderByConfirm(ActionHelper.getSetValuesFromModel(directOrder), params);
							
							LoggerHelper.writeLog(DirectOrder.class, "update", 
										"批量修改了[商品订单]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(null,directOrder,false)
										,null);
							
							
							/************CTRL_UPDATE_BY_PARAMS************/
							/************CTRL_UPDATE_BY_PARAMS************/
						}else if(!Utils.empty(ids)){//根据ids批量更新
							Map params = new HashMap();
							params.put("idIn",ids);
							params.put("confirm", 1);
							params.put("definex","1=1");
							
							DirectOrder.updateDirectOrderByConfirm(ActionHelper.getSetValuesFromModel(directOrder), params);
							
							LoggerHelper.writeLog(DirectOrder.class, "update", 
										"批量修改了[商品订单]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(null,directOrder,false)
										,null);
							
							
							/************CTRL_UPDATE_BY_IDS************/
							/************CTRL_UPDATE_BY_IDS************/
						}else{
							if(Utils.empty(Utils.getString("all"))){//修改对象非空的字段
								
								oldDirectOrder=DirectOrder.where.id(directOrder.getId()).get();
								if(oldDirectOrder==null){
									throw new DefineException("对不起，你没有权限修改当前数据");
								}
								
								DirectOrder.updateDirectOrder$NotNull(directOrder);
								
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
									
								
								
								
								
								LoggerHelper.writeLog(DirectOrder.class, "update", 
										"修改了[商品订单]["+oldDirectOrder.getNo()+"]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(oldDirectOrder, directOrder,false)
										,directOrder.getId());
								
								
								/************CTRL_UPDATE_NOT_NULL************/
								/************CTRL_UPDATE_NOT_NULL************/
							}else{//修改对象全部字段
								
								oldDirectOrder=DirectOrder.where.id(directOrder.getId()).get();
								if(oldDirectOrder==null){
									throw new DefineException("对不起，你没有权限修改当前数据");
								}
								//设置默认值
								
									
									
								
									
									
								
									
									
								
									
									
									
								
									
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								directOrder.setLatitude(oldDirectOrder.getLatitude());	
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								
									
									
								directOrder.setGetOrderTime(oldDirectOrder.getGetOrderTime());	
									
								
									
									
								directOrder.setAddTime(oldDirectOrder.getAddTime());	
									
								
									
									
								
									
									
								
									
									
								
									
									
								directOrder.setStreet(oldDirectOrder.getStreet());	
									
								
									
									
								
									
									
								
									
									
								
									
									
								directOrder.setUpdateTime(oldDirectOrder.getUpdateTime());	
									
								
									
									
								
									
									
								directOrder.setDx(oldDirectOrder.getDx());	
									
								
								//设置默认值
								setDefaultValue(directOrder,"update");
								
															
								
								
								//从oldDirectOrder同步directOrder未set过的值
								directOrder.mergeSet(oldDirectOrder);
										
								DirectOrder.updateDirectOrder(directOrder);
								
								
								LoggerHelper.writeLog(DirectOrder.class, "update", 
										"修改了[商品订单]["+oldDirectOrder.getNo()+"]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(oldDirectOrder, directOrder,true)
										,directOrder.getId());
								
								
								/************CTRL_UPDATE_ALL************/
								/************CTRL_UPDATE_ALL************/
							}
						}
						
						/************CTRL_CODE_UPDATE************/
						/************CTRL_CODE_UPDATE************/
						return null;
					}
				});
				
			}else{
				throw new DefineException("repeat-submit-error","对不起，请勿重复提交"+(10-((new Date().getTime()-lastToken.getTime())/1000))+"秒后再试");
			}
			
			/************CTRL_AFTER_UPDATE************/
			/************CTRL_AFTER_UPDATE************/
			return Protocol.create(true,"修改[商品订单]数据成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	@limitVal(8)//删除权限
  	@RequestMapping("/manage/goods/directorder.delete.do")
  	public Protocol delete() {
  		try{
			DirectOrder.execute(new Function(){
				public <T> T execute(Object... arg0){
					Long pid=Utils.getLong("id");
					Long[] ids=new Long[]{pid};
					String strIds=Utils.getString( "ids");
					if(!Utils.empty(strIds) && !strIds.trim().equals("")){//批量删除
						String[] array = strIds.split(",");
						ids=new Long[array.length];
						for(int i=0;i<array.length;i++)
							ids[i]=Long.valueOf(array[i]);
					}
					if(ids.length==0){
						throw new DefineException("args-id-null","参数错误");
					}
					for(Long id:ids){
						DirectOrder directOrder = null;
						
						directOrder=DirectOrder.where.id(id).get();
						if(directOrder==null){
							throw new DefineException("对不起，你没有权限修改当前数据");
						}
						
						DirectOrder.delete(id);						
						
						if(directOrder!=null)//记录操作日志
							LoggerHelper.writeLog(DirectOrder.class,"del","删除了[商品订单]["+directOrder.getNo()+"]",LoginHelper.getUserId(), directOrder);
						
						
						/************CTRL_CODE_DEL************/
						/************CTRL_CODE_DEL************/
					}
					return null;
				}
			});
			return Protocol.create(true,"删除操作成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	
  	
		
	
		
	
		
	
		
	
		
	
		
		
	private void saveDetails(DirectOrder directOrder){
		List<OrderDetails> exists = directOrder.get$details();
		Set<Long> ids = new HashSet();
		for(OrderDetails entity:exists){
			ids.add(entity.getId());
		} 
		List<Map> array = (List<Map>) Utils.eval(directOrder.getDetails$());
		for(Map map:array){
			OrderDetails entity = Utils.getObject(map, null, OrderDetails.class);
			entity.setDefaultValue((entity.getId()==null) ? "insert" : "update");
			entity.setOrders(directOrder.getId());
			if(entity.getId()!=null){
				entity.update();
			}else{
				entity = entity.save();
			}
			ids.remove(entity.getId());
		}
		if(!ids.isEmpty()){
			for(Long id:ids){
				OrderDetails.delete(id);
			}
		}
	}
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
		
	
  	  	
  	

	/**
	 * 定义表单平台发货提交
	 */
	@RequestMapping("/manage/goods/directorder.send.do")
	public Protocol send(){
		try{
			Protocol protocol = Protocol.create(true);
			final String requestToken = Utils.getString("directOrderToken");
			final Date lastToken = Utils.getSession(requestToken);
			if(lastToken==null || (new Date().getTime()-lastToken.getTime())>10000){
				if(requestToken!=null)Utils.setSession(requestToken,new Date());//放入Token时间戳
				protocol = DirectOrder.execute(new Function(){
					public <T> T execute(Object... arg0){
						DirectOrder directOrder = Utils.getObject("directOrder", DirectOrder.class);
						
						DirectOrder dbDirectOrder = null;						
						dbDirectOrder=DirectOrder.where.id(directOrder.getId()).get();
						if(dbDirectOrder==null){
							throw new DefineException("对不起，你没有权限修改当前数据");
						}
						
						
						//页面传入参数：directOrder.logisMode,directOrder.courier,
						
							
						//平台发贷：if(Utils.equals(Utils.getString("directOrder.status"),"3")){}
							
						
						
						/************CTRL_FORM_CODE_send************/
						/************CTRL_FORM_CODE_send************/
						
						directOrder.update();
						
							
						LoggerHelper.writeLog(DirectOrder.class, "modify", 
							"操作了[平台发货]["+dbDirectOrder.getNo()+"]",
							LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(dbDirectOrder,directOrder,false)
							,dbDirectOrder.getId());
							
						
						
						return null;
					}
				});
				
			}else{
				throw new DefineException("repeat-submit-error","对不起，请勿重复提交"+(10-((new Date().getTime()-lastToken.getTime())/1000))+"秒后再试");
			}
			
			
			/************CTRL_FORM_RETURN_send************/
			/************CTRL_FORM_RETURN_send************/
			if(protocol!=null){
				return protocol;
			}
			
			return Protocol.create(true,"[平台发货]操作成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
	}

	/**
	 * 定义表单退款审核通过提交
	 */
	@RequestMapping("/manage/goods/directorder.adopt.do")
	public Protocol adopt(){
		try{
			Protocol protocol = Protocol.create(true);
			final String requestToken = Utils.getString("directOrderToken");
			final Date lastToken = Utils.getSession(requestToken);
			if(lastToken==null || (new Date().getTime()-lastToken.getTime())>10000){
				if(requestToken!=null)Utils.setSession(requestToken,new Date());//放入Token时间戳
				protocol = DirectOrder.execute(new Function(){
					public <T> T execute(Object... arg0){
						DirectOrder directOrder = Utils.getObject("directOrder", DirectOrder.class);
						
						DirectOrder dbDirectOrder = null;						
						dbDirectOrder=DirectOrder.where.id(directOrder.getId()).get();
						if(dbDirectOrder==null){
							throw new DefineException("对不起，你没有权限修改当前数据");
						}
						
						
						//页面传入参数：directOrder.refuseRefund,
						
						
						/************CTRL_FORM_CODE_adopt************/
						 AlipyToUser alipyToUser=new AlipyToUser();	
                         Account account=Account.where.member(directOrder.getMember()).get();
                         Map<String,String> result = alipyToUser.alipay2User(directOrder.getNo(), directOrder.getActualPay$(), account.getAlipayNo(), account.getAlipayName());//进行打款
                        if (result.get("success")!=null&&result.get("success").equals("true")) {
                     	   directOrder.refundStatus((short)4);
                     	   
						 WechatMouldUtil wechatMouldUtil=new WechatMouldUtil();
						 Map<String, Object> data=new HashMap<String, Object>();
						 Map<String, Object> data1=new HashMap<String, Object>();
						data1.put("value", directOrder.getNo());
						Map<String, Object> data2=new HashMap<String, Object>();
						data2.put("value", directOrder.getActualPay$());
						data.put("keyword1", data1);
						data.put("keyword2", data2);
						TbMsg msg=new TbMsg(
								directOrder.getMember()//会员
   							 	,"退款成功"+directOrder.getActualPay$()//内容
   							 	,new Date()//时间
   								);
   						msg.save();
                     // wechatMouldUtil.sendWechatmsgToUser(directOrder.getDirectoFormid(), "O2O7Tu7hwVN-oYlfulWL05hPe5TybwdenP3qGfs2jVM", directOrder.get$member().getOpenid(), data);//发送微信小程序消息模板
						}else {
							 WechatMouldUtil wechatMouldUtil=new WechatMouldUtil();
	   						 Map<String, Object> data=new HashMap<String, Object>();
	   						 Map<String, Object> data1=new HashMap<String, Object>();
	   						data1.put("value", directOrder.getActualPay$());
	   						Map<String, Object> data2=new HashMap<String, Object>();
	   						data2.put("value", DateUtils.formatDateTime(new Date()));
	   						Map<String, Object> data3=new HashMap<String, Object>();
	   						data3.put("value", "打款失败");
	   						data.put("keyword1", data1);
	   						data.put("keyword2", data2);
	   						data.put("keyword3", data3);
	                         wechatMouldUtil.sendWechatmsgToUser(directOrder.getDirectoFormid(), "59UYh_i3u90S8AJM-zO-IeIAL2oIP4MprTN-FdB7TFQ", directOrder.get$member().getOpenid(), data);//发送微信小程序消息模板
							directOrder.setErroLog(result.get("des"));
							directOrder.refundStatus((short)1);
							directOrder.update();
							TbMsg msg=new TbMsg(
									directOrder.getMember()//会员
	   							 	,"退款失败"//内容
	   							 	,new Date()//时间
	   								);
	   						msg.save();
							throw new DefineException("对不起，打款失败");
						}
						/************CTRL_FORM_CODE_adopt************/
						
						directOrder.update();
						
							
						LoggerHelper.writeLog(DirectOrder.class, "modify", 
							"操作了[退款审核通过]["+dbDirectOrder.getNo()+"]",
							LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(dbDirectOrder,directOrder,false)
							,dbDirectOrder.getId());
							
						
						
						return null;
					}
				});
				
			}else{
				throw new DefineException("repeat-submit-error","对不起，请勿重复提交"+(10-((new Date().getTime()-lastToken.getTime())/1000))+"秒后再试");
			}
			
			
			/************CTRL_FORM_RETURN_adopt************/
			/************CTRL_FORM_RETURN_adopt************/
			if(protocol!=null){
				return protocol;
			}
			
			return Protocol.create(true,"[退款审核通过]操作成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
	}

	/**
	 * 定义表单退款审核拒绝提交
	 */
	@RequestMapping("/manage/goods/directorder.refuse.do")
	public Protocol refuse(){
		try{
			Protocol protocol = Protocol.create(true);
			final String requestToken = Utils.getString("directOrderToken");
			final Date lastToken = Utils.getSession(requestToken);
			if(lastToken==null || (new Date().getTime()-lastToken.getTime())>10000){
				if(requestToken!=null)Utils.setSession(requestToken,new Date());//放入Token时间戳
				protocol = DirectOrder.execute(new Function(){
					public <T> T execute(Object... arg0){
						DirectOrder directOrder = Utils.getObject("directOrder", DirectOrder.class);
						
						DirectOrder dbDirectOrder = null;						
						dbDirectOrder=DirectOrder.where.id(directOrder.getId()).get();
						if(dbDirectOrder==null){
							throw new DefineException("对不起，你没有权限修改当前数据");
						}
						
						
						//页面传入参数：directOrder.refuseRefund,
						
						
						/************CTRL_FORM_CODE_refuse************/
						 Map<String, Object> data=new HashMap<String, Object>();
  						 Map<String, Object> data1=new HashMap<String, Object>();
  						data1.put("value", directOrder.getActualPay());
  						Map<String, Object> data2=new HashMap<String, Object>();
  						data2.put("value", DateUtils.formatDateTime(new Date()));
  						Map<String, Object> data3=new HashMap<String, Object>();
  						data3.put("value", directOrder.getRefuseRefund());
  						data.put("keyword1", data1);
  						data.put("keyword2", data2);
  						data.put("keyword3", data3);
  						TbMsg msg=new TbMsg(
								directOrder.getMember()//会员
   							 	,"拒绝退款:"+directOrder.getRefuseRefund()//内容
   							 	,new Date()//时间
   								);
   						msg.save();
						/************CTRL_FORM_CODE_refuse************/
						
						directOrder.update();
						
							
						LoggerHelper.writeLog(DirectOrder.class, "modify", 
							"操作了[退款审核拒绝]["+dbDirectOrder.getNo()+"]",
							LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(dbDirectOrder,directOrder,false)
							,dbDirectOrder.getId());
							
						
						
						return null;
					}
				});
				
			}else{
				throw new DefineException("repeat-submit-error","对不起，请勿重复提交"+(10-((new Date().getTime()-lastToken.getTime())/1000))+"秒后再试");
			}
			
			
			/************CTRL_FORM_RETURN_refuse************/
			/************CTRL_FORM_RETURN_refuse************/
			if(protocol!=null){
				return protocol;
			}
			
			return Protocol.create(true,"[退款审核拒绝]操作成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
	}


	@RequestMapping("/manage/goods/directorder.query.do")
	public Protocol query(){
		try{
			Map<String,Object> params = setDefaultSort(ActionHelper.getQueryFormParams(DirectOrder.class));
			
			
			
				
			params.put("merchant",LoginHelper.getLogin().getId());
				
			
			
			String strTerm=Utils.getString("value");//智能搜索时的参数，一般都是主键后面那个字段
			if(!Utils.empty(strTerm)){
				if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
					params.put("id", strTerm.toLowerCase().replaceFirst("id:", ""));					
				else//按标识查询，模糊查询请带%
				{
					
					String strDefinex = "";
					
					strDefinex+=" or no like '%"+strTerm.replaceAll("'", "''")+"%'";
					
					strDefinex="(2=1 "+strDefinex+")";
					params.put("definex",strDefinex);
					
				}
			}
			
			Integer iSize = Utils.getInteger("size",10);
			
			
			/************CTRL_CODE_QUERY************/
			/************CTRL_CODE_QUERY************/
			
			List<DirectOrder> list = DirectOrder.page(0,iSize,params).getResult();
			
			Boolean bObject=Utils.getBoolean("object",false);//是否需要整个数据对象
			List<Map> result = new java.util.ArrayList();
			
			for(DirectOrder directOrder:list){
				Map map = new HashMap();
				map.put("key",directOrder.getId().toString());
				map.put("value", Utils.js(directOrder.getKeyValue()));
				if(bObject==true){
					map.put("object",directOrder);
				}
				
				result.add(map);
			}
			
			
			/************CTRL_AFTER_QUERY************/
			/************CTRL_AFTER_QUERY************/
			
			return Protocol.create().setList(result);
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
	}
  	
  	
	/************CTRL_DEFINE_CODE************/
	/************CTRL_DEFINE_CODE************/
  	
  	/**获取子项列表**/
	public static Map getItems(){
		Map map = new HashMap();
	
	
	
	
	
	
	 
		
		/************CTRL_DEFINE_ITEMS************/
		/************CTRL_DEFINE_ITEMS************/
		return map;
	}
  	
  	/**
	* 设置排序
	**/
  	private Map<String,Object> setDefaultSort(Map<String, Object> params) {
		String strAsc=DirectOrder.C.get(Utils.forMat(Utils.getString("asc")));//升序字段
		params.put("asc", strAsc);//放入查询条件
		String strDesc=DirectOrder.C.get(Utils.forMat(Utils.getString("desc")));//降序字段
		params.put("desc",strDesc);//放入查询条件 
		if(Utils.empty(strAsc) && Utils.empty(strDesc))//如果未传入排序字段
			params.put("none","id");//那么，默认以主键降序，传给Dao层
		return params;
	}
  	/**
	* 设置默认值
	**/
	public void setDefaultValue(DirectOrder directOrder,String type){
		if(type.equals("insert")){//添加时			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			if(directOrder.getAgreement()==null)
				directOrder.setAgreement((short)1);
				
			
			
			
			
			
			
			
			
			
			if(directOrder.getAddTime()==null)
				directOrder.setAddTime(new Date());
				
			
			if(directOrder.getStatus()==null)
				directOrder.setStatus((short)1);
				
			
			
			
			
			
			
			
			if(directOrder.getUpdateTime()==null)
				directOrder.setUpdateTime(new Date());
				
			
			
			
		}else if(type.equals("update")){//编辑时
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			directOrder.setUpdateTime(new Date());
				
			
			
			
		}
	}
	

	/**
	* 设置表单信息
	**/
	public void setFormDataInfo(Protocol protocol,String edittype,DirectOrder directOrder){
		Map model = new HashMap();
		model.put("name","directOrder");
		model.put("caption","商品订单");
		model.put("type","table");
		model.put("icon","icon-weibiaoti11");
		model.put("PK","id");
		model.put("add",true);
		model.put("update",true);
		model.put("details",true);
		List propertys = new ArrayList();
		List submits = new ArrayList();
		model.put("propertys", propertys);
		model.put("submits", submits);	
		protocol.set("model", model);
		if(Utils.empty(edittype)){
		
			 
		
			 
		
			 
		propertys.add(Utils.add("name","orderType").add("cell","attr").add("caption","订单类型").add("input","select").add("primary",false).add("length",2).add("options",new Object[]{Utils.add("text","直接购买订单").add("value","1"),Utils.add("text","余额提货订单").add("value","2")}));
			 
		
			 
		
			 
		
			 
		
			 
		
			 
		
			 
		propertys.add(Utils.add("name","logisMode").add("cell","attr").add("caption","物流方式").add("input","select").add("primary",false).add("length",32).add("options",new Object[]{Utils.add("text","顺丰").add("value","shunfeng"),Utils.add("text","申通").add("value","shentong"),Utils.add("text","圆通").add("value","yuantong"),Utils.add("text","中通").add("value","zhongtong"),Utils.add("text","百世汇通").add("value","huitongkuaidi"),Utils.add("text","百世物流").add("value","baishiwuliu"),Utils.add("text","韵达").add("value","yunda"),Utils.add("text","宅急送").add("value","zhaijisong"),Utils.add("text","天天").add("value","tiantian"),Utils.add("text","德邦").add("value","debangwuliu"),Utils.add("text","国通").add("value","guotongkuaidi"),Utils.add("text","增益").add("value","zengyisudi"),Utils.add("text","速尔").add("value","suer"),Utils.add("text","中铁物流").add("value","ztky"),Utils.add("text","中铁快运").add("value","zhongtiewuliu"),Utils.add("text","能达").add("value","ganzhongnengda"),Utils.add("text","优速").add("value","youshuwuliu"),Utils.add("text","全峰").add("value","quanfengkuaidi"),Utils.add("text","京东").add("value","jd"),Utils.add("text","邮政包裹/平邮").add("value","youzhengguonei"),Utils.add("text","国际包裹").add("value","youzhengguoji"),Utils.add("text","EMS").add("value","ems"),Utils.add("text","EMS-国际件").add("value","emsguoji")}));
			 
		
			 
		
			 
		
			 
		
			 
		propertys.add(Utils.add("name","gender").add("cell","attr").add("caption","性　　别").add("input","select").add("primary",false).add("length",2).add("options",new Object[]{Utils.add("text","男").add("value","1"),Utils.add("text","女").add("value","2")}));
			 
		
			 
		
			 
		propertys.add(Utils.add("name","distributionMode").add("cell","attr").add("caption","配送方式").add("input","select").add("primary",false).add("length",2).add("options",new Object[]{Utils.add("text","到店自提").add("value","1"),Utils.add("text","送货上门").add("value","2")}));
			 
		
			 
		
			 
		propertys.add(Utils.add("name","sType").add("cell","attr").add("caption","接单类型").add("input","select").add("primary",false).add("length",1).add("options",new Object[]{Utils.add("text","配送商接单").add("value","1"),Utils.add("text","退回品牌总部").add("value","2"),Utils.add("text","暂不可接单").add("value","3")}));
			 
		
			 
		
			 
		
			 
		propertys.add(Utils.add("name","paysStatus").add("cell","attr").add("caption","支付情况").add("input","select").add("primary",false).add("length",2).add("options",new Object[]{Utils.add("text","未支付").add("value","0"),Utils.add("text","已支付").add("value","1")}));
			 
		
			 
		
			 
		propertys.add(Utils.add("name","status").add("cell","coner").add("caption","状　　态").add("input","select").add("primary",false).add("length",2).add("options",new Object[]{Utils.add("text","待支付").add("value","1"),Utils.add("text","待发货").add("value","2"),Utils.add("text","待收货/自提").add("value","3"),Utils.add("text","已收货").add("value","4"),Utils.add("text","售后").add("value","5"),Utils.add("text","已取消").add("value","6")}));
			 
		
		}
		
		else if(edittype.equals("send")){
			
			if(true  && (""+directOrder.getStatus()).equals(""+2)){
			
				model.put("title","平台发货");
				
			
				propertys.add(Utils.add("name","no").add("caption","订 单 号").add("input","text").add("primary",false).add("length",32).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","orderType").add("caption","订单类型").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")).add("options",new Object[]{Utils.add("text","直接购买订单").add("value","1"),Utils.add("text","余额提货订单").add("value","2")}));
			

			
				propertys.add(Utils.add("name","member").add("caption","会员信息").add("input","query").add("primary",false).add("length",8).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")).add("relate","Member"));
			

			
				propertys.add(Utils.add("name","remarks").add("caption","备注信息").add("input","textarea").add("primary",false).add("length",256).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","address").add("caption","送货地址").add("input","text").add("primary",false).add("length",64).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","regionCity").add("caption","所属地区").add("input","tree").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")).add("relate","Region"));
			

			
				propertys.add(Utils.add("name","consigneeName").add("caption","收货人姓名").add("input","text").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","receivingTelephoneNumber").add("caption","收货电话号").add("input","text").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","selfAddress").add("caption","自提地址").add("input","text").add("primary",false).add("length",128).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","logisMode").add("caption","物流方式").add("input","select").add("primary",false).add("length",32).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","顺丰").add("value","shunfeng"),Utils.add("text","申通").add("value","shentong"),Utils.add("text","圆通").add("value","yuantong"),Utils.add("text","中通").add("value","zhongtong"),Utils.add("text","百世汇通").add("value","huitongkuaidi"),Utils.add("text","百世物流").add("value","baishiwuliu"),Utils.add("text","韵达").add("value","yunda"),Utils.add("text","宅急送").add("value","zhaijisong"),Utils.add("text","天天").add("value","tiantian"),Utils.add("text","德邦").add("value","debangwuliu"),Utils.add("text","国通").add("value","guotongkuaidi"),Utils.add("text","增益").add("value","zengyisudi"),Utils.add("text","速尔").add("value","suer"),Utils.add("text","中铁物流").add("value","ztky"),Utils.add("text","中铁快运").add("value","zhongtiewuliu"),Utils.add("text","能达").add("value","ganzhongnengda"),Utils.add("text","优速").add("value","youshuwuliu"),Utils.add("text","全峰").add("value","quanfengkuaidi"),Utils.add("text","京东").add("value","jd"),Utils.add("text","邮政包裹/平邮").add("value","youzhengguonei"),Utils.add("text","国际包裹").add("value","youzhengguoji"),Utils.add("text","EMS").add("value","ems"),Utils.add("text","EMS-国际件").add("value","emsguoji")}));
			

			
				propertys.add(Utils.add("name","courier").add("caption","快递单号").add("input","text").add("primary",false).add("length",32).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			

				
					
				submits.add(Utils.add("name","directOrder.status").add("title","平台发贷").add("value","3").add("icon","icon-libreoffice"));
					
				
			
			}else{
				protocol.setSuccess(false);
				protocol.setMessage("当前流程不在'平台发货'");
			}
			
		}
		
		else if(edittype.equals("adopt")){
			
			if(true  && (""+directOrder.getRefundStatus()).equals(""+1)){
			
				model.put("title","退款审核通过");
				
			
				propertys.add(Utils.add("name","no").add("caption","订 单 号").add("input","text").add("primary",false).add("length",32).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","merchant").add("caption","所属品牌").add("input","query").add("primary",false).add("length",8).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")).add("relate","Merchant"));
			

			
				propertys.add(Utils.add("name","orderType").add("caption","订单类型").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","member").add("caption","会员信息").add("input","query").add("primary",false).add("length",8).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")).add("relate","Member"));
			

			
				propertys.add(Utils.add("name","receivingTelephoneNumber").add("caption","收货电话号").add("input","text").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","totalSum").add("caption","总 金 额").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","actualPay").add("caption","实际支付").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","paysStatus").add("caption","支付情况").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","refundStatus").add("caption","退款状态").add("input","select").add("primary",false).add("length",1).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","meRefundMoney").add("caption","会员退款理由").add("input","textarea").add("primary",false).add("length",128).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","refuseRefund").add("caption","拒绝退款理由").add("input","textarea").add("primary",false).add("length",128).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			

				
				submits.add(Utils.add("name","submiter").add("value","完成").add("title","完成").add("icon","icon-weibiaoti8"));
				
			
			}else{
				protocol.setSuccess(false);
				protocol.setMessage("当前流程不在'退款审核通过'");
			}
			
		}
		
		else if(edittype.equals("refuse")){
			
			if(true  && (""+directOrder.getRefundStatus()).equals(""+1)){
			
				model.put("title","退款审核拒绝");
				
			
				propertys.add(Utils.add("name","no").add("caption","订 单 号").add("input","text").add("primary",false).add("length",32).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","merchant").add("caption","所属品牌").add("input","query").add("primary",false).add("length",8).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")).add("relate","Merchant"));
			

			
				propertys.add(Utils.add("name","orderType").add("caption","订单类型").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","member").add("caption","会员信息").add("input","query").add("primary",false).add("length",8).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")).add("relate","Member"));
			

			
				propertys.add(Utils.add("name","receivingTelephoneNumber").add("caption","收货电话号").add("input","text").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","totalSum").add("caption","总 金 额").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","actualPay").add("caption","实际支付").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","paysStatus").add("caption","支付情况").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","refundStatus").add("caption","退款状态").add("input","select").add("primary",false).add("length",1).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","meRefundMoney").add("caption","会员退款理由").add("input","textarea").add("primary",false).add("length",128).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"readonly":"readonly")));
			

			
				propertys.add(Utils.add("name","refuseRefund").add("caption","拒绝退款理由").add("input","textarea").add("primary",false).add("length",128).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			

				
				submits.add(Utils.add("name","submiter").add("value","完成").add("title","完成").add("icon","icon-weibiaoti8"));
				
			
			}else{
				protocol.setSuccess(false);
				protocol.setMessage("当前流程不在'退款审核拒绝'");
			}
			
		}
		
		else{
			
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","no").add("caption","订 单 号").add("input","text").add("primary",false).add("length",32).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","orderType").add("caption","订单类型").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","直接购买订单").add("value","1"),Utils.add("text","余额提货订单").add("value","2")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","member").add("caption","会员信息").add("input","query").add("primary",false).add("length",8).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("relate","Member"));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"readonly")).equals("none")){
				propertys.add(Utils.add("name","details").add("caption","订单明细").add("input","grid").add("primary",false).add("length",0).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"readonly")).add("relate","OrderDetails").add("options",new Object[]{Utils.add("text","goodsNumber").add("value","query").add("depict","商品编号"),Utils.add("text","name").add("value","text").add("depict","商品名称"),Utils.add("text","price").add("value","menoy").add("depict","商品价格"),Utils.add("text","number").add("value","number").add("depict","数量"),Utils.add("text","status").add("value","select").add("depict","状态").add("data","[{\"text\":\"正常\",\"value\":\"1\"},{\"text\":\"无效\",\"value\":\"0\"}]")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","remarks").add("caption","备注信息").add("input","textarea").add("primary",false).add("length",256).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","address").add("caption","送货地址").add("input","text").add("primary",false).add("length",64).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","logisMode").add("caption","物流方式").add("input","select").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","顺丰").add("value","shunfeng"),Utils.add("text","申通").add("value","shentong"),Utils.add("text","圆通").add("value","yuantong"),Utils.add("text","中通").add("value","zhongtong"),Utils.add("text","百世汇通").add("value","huitongkuaidi"),Utils.add("text","百世物流").add("value","baishiwuliu"),Utils.add("text","韵达").add("value","yunda"),Utils.add("text","宅急送").add("value","zhaijisong"),Utils.add("text","天天").add("value","tiantian"),Utils.add("text","德邦").add("value","debangwuliu"),Utils.add("text","国通").add("value","guotongkuaidi"),Utils.add("text","增益").add("value","zengyisudi"),Utils.add("text","速尔").add("value","suer"),Utils.add("text","中铁物流").add("value","ztky"),Utils.add("text","中铁快运").add("value","zhongtiewuliu"),Utils.add("text","能达").add("value","ganzhongnengda"),Utils.add("text","优速").add("value","youshuwuliu"),Utils.add("text","全峰").add("value","quanfengkuaidi"),Utils.add("text","京东").add("value","jd"),Utils.add("text","邮政包裹/平邮").add("value","youzhengguonei"),Utils.add("text","国际包裹").add("value","youzhengguoji"),Utils.add("text","EMS").add("value","ems"),Utils.add("text","EMS-国际件").add("value","emsguoji")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","longitude").add("caption","经　　度").add("input","position").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","regionCity").add("caption","所属地区").add("input","tree").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("relate","Region"));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","consigneeName").add("caption","收货人姓名").add("input","text").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","receivingTelephoneNumber").add("caption","收货电话号").add("input","text").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","gender").add("caption","性　　别").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","男").add("value","1"),Utils.add("text","女").add("value","2")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","courier").add("caption","快递单号").add("input","text").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","distributionMode").add("caption","配送方式").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","到店自提").add("value","1"),Utils.add("text","送货上门").add("value","2")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","distributor").add("caption","配 送 商").add("input","query").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("relate","Distributor"));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","sType").add("caption","接单类型").add("input","select").add("primary",false).add("length",1).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","配送商接单").add("value","1"),Utils.add("text","退回品牌总部").add("value","2"),Utils.add("text","暂不可接单").add("value","3")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","selfAddress").add("caption","自提地址").add("input","text").add("primary",false).add("length",128).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","dispatFee").add("caption","配 送 费").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","coupon").add("caption","使用优惠券").add("input","query").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("relate","Coupon"));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","useProductVouchers").add("caption","使用产品券").add("input","text").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","couponFree").add("caption","优惠卷抵扣").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","productFree").add("caption","产品卷抵扣").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","totalSum").add("caption","总 金 额").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","actualPay").add("caption","实际支付").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","paysStatus").add("caption","支付情况").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","未支付").add("value","0"),Utils.add("text","已支付").add("value","1")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","agreement").add("caption","支付协议").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","同意").add("value","1"),Utils.add("text","不同意").add("value","2")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","processor").add("caption","实际处理方").add("input","select").add("primary",false).add("length",1).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","待确定").add("value","0"),Utils.add("text","品牌总部").add("value","1"),Utils.add("text","配送商").add("value","2")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","afterSType").add("caption","售后类型").add("input","select").add("primary",false).add("length",2).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","暂无").add("value","0"),Utils.add("text","投诉").add("value","1"),Utils.add("text","退款").add("value","2")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","complaint").add("caption","投诉理由").add("input","textarea").add("primary",false).add("length",256).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","dealted").add("caption","投诉是处理").add("input","select").add("primary",false).add("length",1).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","无投诉").add("value","0"),Utils.add("text","未处理").add("value","1"),Utils.add("text","已处理").add("value","2")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","refundStatus").add("caption","退款状态").add("input","select").add("primary",false).add("length",1).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","无").add("value","0"),Utils.add("text","待审核").add("value","1"),Utils.add("text","同意退款").add("value","2"),Utils.add("text","拒绝退款").add("value","3"),Utils.add("text","已退款").add("value","4")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","refuseRefund").add("caption","拒绝退款理由").add("input","textarea").add("primary",false).add("length",128).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","meRefundMoney").add("caption","会员退款理由").add("input","textarea").add("primary",false).add("length",128).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"readonly")).equals("none")){
				propertys.add(Utils.add("name","getOrderTime").add("caption","接单时间").add("input","datetime").add("primary",false).add("length",19).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"readonly")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"none")).equals("none")){
				propertys.add(Utils.add("name","addTime").add("caption","添加时间").add("input","datetime").add("primary",false).add("length",19).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"none")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"editable")).equals("none")){
				propertys.add(Utils.add("name","status").add("caption","状　　态").add("input","select").add("primary",false).add("length",2).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"editable")).add("options",new Object[]{Utils.add("text","待支付").add("value","1"),Utils.add("text","待发货").add("value","2"),Utils.add("text","待收货/自提").add("value","3"),Utils.add("text","已收货").add("value","4"),Utils.add("text","售后").add("value","5"),Utils.add("text","已取消").add("value","6")}));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","merchant").add("caption","品 牌 商").add("input","query").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("relate","Merchant"));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","jxs").add("caption","经 销 商").add("input","text").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","distributorIncome").add("caption","配送商收益").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","directoFormid").add("caption","formId").add("input","text").add("primary",false).add("length",32).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","erroLog").add("caption","打款原因").add("input","text").add("primary",false).add("length",2000).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}

			submits.add(Utils.add("name","submiter").add("value","完成").add("title","完成").add("icon","icon-weibiaoti8"));
		}
	}
  
}